﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Globalization;
using System.Threading;
using System.Configuration;

namespace Global
{
    public partial class _Default : System.Web.UI.Page
    {
        
        protected override void InitializeCulture()
        {
            base.InitializeCulture();
            CultureInfo selectedCulture=new CultureInfo(ConfigurationManager.AppSettings["Localization_DefaultLanguage"]);
            HttpCookie cookie = Request.Cookies.Get("lang");
            DateTime cookieExpiration=DateTime.Now.AddDays(Convert.ToInt32(ConfigurationManager.AppSettings["Localization_cookieExpirationinDays"]));

            if (Request.QueryString["lang"] != null)
            {
                selectedCulture = new CultureInfo(Request.QueryString["lang"]);
            cookie = new HttpCookie("lang", selectedCulture.Name) { Expires = cookieExpiration };
            Response.Cookies.Add(cookie);
        }
            else if(cookie!=null)
            {
                selectedCulture=new CultureInfo(cookie.Value);
            }
            else
            {

                cookie = new HttpCookie("lang", selectedCulture.Name) { Expires = cookieExpiration };
                Response.Cookies.Add(cookie);

            }
            Thread.CurrentThread.CurrentUICulture = selectedCulture; 
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedCulture.Name);
              





  
        }
    }
}
